package contracts.simpleCodingQuiz

import org.springframework.cloud.contract.spec.Contract

Contract.make {
    request {
        method("POST")
        url("/api/simpleCodingQuizzes")
        headers {
            contentType(applicationJsonUtf8())
            header("id", 1)
        }
        body("""
            {
                "definitionRepo":"https://github.com/tws-online-quiz/lcd-digit-node.git",
                "description":"我是题目描述",
                "title":"java",
                "stackId":1,
                "quizGroupId":1,
                "makerId":5,
            }
        """)
        bodyMatchers {
            jsonPath('$.definitionRepo', byRegex("[\\s\\S]+"))
            jsonPath('$.description', byRegex("[\\s\\S]+"))
            jsonPath('$.title', byRegex("[\\s\\S]+"))
            jsonPath('$.stackId', byRegex(number()))
            jsonPath('$.quizGroupId', byRegex(number()))
            jsonPath('$.makerId', byRegex(number()))
        }

    }
    response {
        status(201)
        body("""
            {
                "id": 3,
                "definitionRepo": "https://github.com/tws-online-quiz/lcd-digit-node.git",
                "description": "我是题目描述",
                "makerId": 5,
                "quizGroupId": 1,
                "stackId": 1,
            }
        """)
        bodyMatchers {
            jsonPath('$.id', byRegex(number()))
            jsonPath('$.description', byRegex(nonBlank()))
            jsonPath('$.makerId', byRegex(number()))
            jsonPath('$.definitionRepo', byRegex(nonBlank()))
            jsonPath('$.quizGroupId', byRegex(number()))
            jsonPath('$.stackId', byRegex(number()))
        }
        headers {
            contentType(applicationJsonUtf8())
        }
    }
}
